package cn.cloudreal.cbms.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.opensymphony.xwork2.ActionSupport;

public class UploadExcelAction extends ActionSupport {
	//工具
	private Excel2DB excel2DB; 
	
	
	public void setExcel2DB(Excel2DB excel2db) {
		excel2DB = excel2db;
	}

	private File file;
	private String fileFileName;
	private String fileContentType;

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	@Override
	public String execute() throws Exception {
		
		System.out.println("------------------------------UploadExcelAction--------------------------------");
		InputStream is = new FileInputStream(file);		
		excel2DB.insertExcelData2DB(is);
		
		
//		String path = ServletActionContext.getServletContext().getRealPath("/");
//		File newFile = new File("e:", this.getFileFileName());
//		OutputStream os = new FileOutputStream(newFile);
//		byte[] buffer = new byte[400];
//		int length = 0;
//		while ((length = is.read(buffer)) > 0)
//			os.write(buffer, 0, length);
//		os.close();
		is.close();
		return "success";
	}
}
